package com.cbtx.receiver

import android.content.Context

/**
 * author : joker.peng
 * e-mail : joker@fiture.com
 * date   : 2021/7/1 3:42 PM
 * desc   :
 */
class ReceiverManager(private val context: Context) : IReceiverManager {

    companion object {
        private const val TAG = "ReceiverManager"
    }

    override val qqMusic: IQQMusicCollection by lazy { QQMusicCollection() }
    override val app: IAppCollection by lazy { AppCollection() }
    override val io: IIOCollection by lazy { IOCollection() }

    private val receiverList: MutableList<BaseReceiver> by lazy {
        mutableListOf(
            AppOperationStatusReceiver(context),
            QQMusicReceiver(context),
            BlueToothReceiver(context),
            NetworkReceiver(context),
            KuyunLiveReceiver(context),
            SignalChangeReceiver(context),
            UsbReceiver(context),
            SignalChangeAndroidPReceiver(context),
            NFCReceiver(context),
            RcReceiver(context)
        )
    }

    override fun register() {
        init(context)
        for (receiver in receiverList) {
            LogUtils.d(TAG, "注册监听：$receiver")
            receiver.register()
        }
    }

    override fun unRegister() {
        for (receiver in receiverList) {
            if (receiver is SignalChangeAndroidPReceiver) {
                receiver.release()
            }
            receiver.unRegister()
        }
    }
}